package hxg.stream;

import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author HeXiangGuang
 * @create 2021-06-25 18:05
 * 文件输入流
 */
public class Demo1 {
    public static void main(String[] args) throws IOException {
        //1创建FileInputStream,并指定文件路径
        FileInputStream fis = new FileInputStream("d:\\bbb.txt");
        int data = 0;
        //2读取文件
        //2.1一次读取一个字节
/*        while ((data = fis.read())!=-1){
            System.out.print((char)data);
        }*/
        //2.1一次读取多个字节

        byte[] buf = new byte[3];
//        buf[1] = 89;
//        System.out.println((buf));
/*        System.out.println("读完文件之前"+new String(buf));
        int count = fis.read(buf);
        System.out.println("读完文件之后"+new String(buf));
        System.out.println(count);
        int count2 = fis.read(buf);
        System.out.println("读完文件之后"+new String(buf));
        System.out.println(count2);
        int count3 = fis.read(buf);
        System.out.println("读完文件之后"+new String(buf,0,count3));
        System.out.println(count3);*/
        int count = 0;
        while ((count=fis.read(buf))!=-1){
            //从数组的0位置开始读读取count个
            System.out.println(new String(buf,0,count));
        }
        //3关闭
        fis.close();
        System.out.println("执行完毕");
    }
}
